/**
 * Created by Julia on 2016/5/12.
 */

define(['jquery', 'appLocalStorage', 'appMessageBox', 'appConst'], function ($, appLocalStorage, msgBox, appConst) {
    return {
        searchYields: function (param, callback, errCallBack) {
            $.ajax({
                url: 'yield/queryYields',
                type: 'POST',
                dataType: 'JSON',
                data: param,
                success: function (data) {
                    if (data.code == 0) {
                        msgBox.errorBox(data.message);
                        if (typeof errCallBack == 'function') {
                            errCallBack();
                        }
                    } else {
                        if (typeof callback == 'function') {
                            callback(data.body);
                        }
                    }
                },
                error: function (e) {
                    if (e.status == 401) {
                        msgBox.sessionFailureBox();
                    }
                    if (e.status == 500) {
                        msgBox.serverFailureBox();
                    }
                    if (e.status == 404) {
                        msgBox.pathFailureBox();
                    }
                    if (typeof errCallBack == 'function') {
                        errCallBack();
                    }
                }
            });
        },
        searchAttributes: function (param, callback, errCallBack) {
            $.ajax({
                url: 'yield/queryAttributeYield',
                type: 'POST',
                dataType: 'JSON',
                data: param,
                success: function (data) {
                    if (data.code == 0) {
                        msgBox.errorBox(data.message);
                        if (typeof errCallBack == 'function') {
                            errCallBack();
                        }
                    } else {
                        if (typeof callback == 'function') {
                            callback(data.body);
                        }
                    }
                },
                error: function (e) {
                    if (e.status == 401) {
                        msgBox.sessionFailureBox();
                    }
                    if (e.status == 500) {
                        msgBox.serverFailureBox();
                    }
                    if (e.status == 404) {
                        msgBox.pathFailureBox();
                    }
                    if (typeof errCallBack == 'function') {
                        errCallBack();
                    }
                }
            });
        }
    }
});